package com.ityaluji.BFS;

import java.util.LinkedList;
import java.util.Queue;

class node{
    int x;
    int dep;
    public node(int x,int dep){
        this.x=x;
        this.dep=dep;
    }
}

public class duilie {
    static int[][] a={
            //A B C D E F G
            {0,0,1,1,0,1,0},//A
            {0,0,1,0,0,0,0},//B
            {1,1,0,1,0,0,0},//C
            {1,0,1,0,0,0,0},//D
            {0,0,0,0,0,0,1},//E
            {1,0,0,0,0,0,1},//F
            {0,0,0,0,1,1,0},//G
    };
    static boolean[] vis=new boolean[7];
    static int mdep=0;
    /*
    广度优先搜索
    1.先进先出
    2.标记-防止重复搜索
    3.邻接矩阵（邻接点）
     */
    public static void bfs(){
        Queue<node> q=new LinkedList<>();
        q.offer(new node(0,1));
        vis[0]=true;
        while(!q.isEmpty()){
            node tmp=q.poll();
            mdep=Math.max(mdep,tmp.dep);
            System.out.print((char)(tmp.x+'A')+" ");
            for(int i=0;i<7;i++){
                if(a[tmp.x][i]==1&&!vis[i]){
                    q.offer(new node(i,tmp.dep+1));
                    vis[i]=true;
                }
            }
        }
    }

    public static void main(String[] args) {
        bfs();
        System.out.println();
        System.out.println(mdep);
    }
}
